<?php
require_once ("includes/table-main.php");

class Table_main_entry extends Table_main{
function Table_main_entry(){
	$this->item_a_page = 5;
	$this->Table_main('home');	
}
	
function mysql_string(){
	return 'SELECT * FROM entry ORDER BY date_created DESC';	
}

// trả về true nếu nội dung quá dài
private function split_content(&$content){
	$max_length = 201;
	if (strlen($content) > $max_length){
		$content = substr($content,0,$max_length);
		return true;
	} else {
		return false;
	}
}
	
function a_row($num_row,$num_item,$data){
	$html_entry = <<<HTML
<div class="entry">                
    <div class="entry-title">%s</div>
    <div class="entry-number">%s</div>                
    <div class="clear"></div>
    %s
    %s
</div>
HTML;

	$html_readmore = <<<HTML
	<div class="read-more"><a href="main.php?view=entry&id=%s">đọc thêm...</a></div>
HTML;

	$html = sprintf($html_entry,$data['title'],$num_item,'%s','%s');
	
	$content = $data['content'];	
	if ($this->split_content($content)){
		$html_readmore = sprintf($html_readmore,$data['entry_id']);
		$html = sprintf($html,nl2br($content).'...',$html_readmore);
	} else {
		$html = sprintf($html,nl2br($content),'');	
	}
	return $html;
}
}

$_table_main_entry = new Table_main_entry();
$_table_main_entry->html();

?>